﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Media;

namespace DXApp.Utils
{
    /// <summary>
    /// 遮罩装饰
    /// </summary>
    public class ShadeAdorner: BaseAdorner
    {
        private Grid _grid;
        public ShadeAdorner(UIElement adornedElement) : base(adornedElement)
        {
            this._grid = new Grid()
            {
                Opacity = 0.2,
                Background = new SolidColorBrush(Colors.Black),
            };
            VisualChildrenCollection.Add(_grid);
        }

        /// <summary>
        /// 绘制区域
        /// </summary>
        /// <param name="finalSize"></param>
        /// <returns></returns>
        protected override Size ArrangeOverride(Size finalSize)
        {
            _grid.Arrange(new Rect(0, 0, finalSize.Width, finalSize.Height));
            return base.ArrangeOverride(finalSize);
        }

        /// <summary>
        /// 设置是否可见
        /// </summary>
        /// <param name="visibility">是否可见</param>
        public void SetVisibility(Visibility visibility)
        {
            _grid.Visibility = visibility;
        }

        /// <summary>
        /// 设置是否可见
        /// </summary>
        /// <param name="visibility"></param>
        /// <param name="color"></param>
        public void SetVisibility(Visibility visibility, Color color)
        {
            _grid.Background = new SolidColorBrush(color);
            _grid.Visibility = visibility;
        }
    }
}
